package threading;

/**
 * @author krystal
 * @date 2022/11/23 10:22
 */
public class Demo11 {
    public static void main(String[] args) {
            Thread t=new Thread(()->{
                while (!Thread.currentThread().isInterrupted()){
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        //e.printStackTrace();
                        break;
                    }
                }
                System.out.println("t线程执行完了");
            });
            t.start();

            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            t.interrupt();
            System.out.println("设置让t线程结束");
        }
}
